import {
	ref
} from 'vue'

export function useCountdown(seconds) {
	const countdown = ref(seconds)
	const isCounting = ref(false)
	let timer = null

	const startCountdown = () => {
		if (isCounting.value) return
		isCounting.value = true
		countdown.value = seconds
		timer = setInterval(() => {
			countdown.value--
			if (countdown.value <= 0) {
				clearInterval(timer)
				isCounting.value = false
			}
		}, 1000)
	}

	return {
		countdown,
		isCounting,
		startCountdown
	}
}